package org.example;

import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User:何人亮
 * Date:2024-11-08
 * 16:38
 */
public class Test {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        int min=sc.nextInt();
        String[] s=new String[n];
        int[] arr=new int[n];
        String ss=sc.nextLine();
        for (int i = 0; i < n; i++) {
            s[i]=sc.next();
            arr[i]=sc.nextInt();
        }
        int count=0;
        Queue<Integer> queueint=new LinkedList<>();
        Queue<String> queueStr=new LinkedList<>();
        int len=arr.length;
        for (int i=0;i<len;i++){
            queueint.add(arr[i]);
            queueStr.add(s[i]);
        }
    while(!queueint.isEmpty()){

        int ni= queueint.poll();
        String s1=queueStr.poll();
        if(ni<=min){
            count+=ni;
            System.out.println(s1+" "+count);
        }else{
            count+=min;
            ni-=min;
            queueint.add(ni);
            queueStr.add(s1);
        }
    }
    }
}
